<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="110px">
        <el-form-item label="交办时间" prop="createDay">
          <el-date-picker v-model="queryParams.createDay" type="date" value-format="yyyy-MM-dd" placeholder="选择日期"  @keyup.enter.native="handleQuery" ></el-date-picker>
        </el-form-item>
        <el-form-item label="投诉技师" prop="jishiNickName">
          <el-input v-model="queryParams.jishiNickName" placeholder="请输入投诉技师" clearable size="small"
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="投诉类型" prop="tousuType">
          <el-select multiple v-model="queryParams.tousuType" placeholder="请选择问题分类">
            <el-option v-for="contract in tousuTypeArray" :key="contract.dictValue" :label="contract.dictLabel"
              :value="contract.dictLabel"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="解决类型" prop="handleType">
          <el-select clearable v-model="queryParams.handleType" placeholder="请选择投诉类型">
            <el-option v-for="contract in handleTypeArray" :key="contract.dictValue" :label="contract.dictLabel"
              :value="contract.dictValue"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="tabList" @selection-change="handleSelectionChange">
        <el-table-column label="交办时间" align="center" prop="createTime" />
        <el-table-column label="投诉技师" align="center" prop="jishiNickName" />
        <el-table-column label="投诉类型" align="center" prop="tousuType" />
        <el-table-column label="投诉内容" align="center" prop="tousuDesc">
          <template slot-scope="scope">
            <div @click="lookTousuDesc(scope.row)" style="color:cornflowerblue;cursor: pointer;">查看</div>
          </template>
        </el-table-column>
        <el-table-column label="投诉截图" align="center" prop="imgUrl">
          <template slot-scope="scope">
            <div @click="imgUrlClick(scope.row)" style="color:cornflowerblue;cursor: pointer;">查看</div>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" prop="">
          <template slot-scope="scope">
            <div v-if="scope.row.tousuStatus == 1" style="color:cornflowerblue;">
            <span @click="replyClick(scope.row)" style="margin-right:10px;cursor: pointer;" v-hasPermi="['tousu:tousu:reply']">回复</span>
            <span @click="applyClick(scope.row)" style="cursor: pointer;" v-hasPermi="['tousu:tousu:complain']">申请退款</span></div>
            <div v-else-if="scope.row.tousuStatus == 2 && scope.row.handleType==1 " >已回复</div>
            <div v-else-if="scope.row.tousuStatus == 2 && scope.row.handleType == 2 && scope.row.orderStatus !=12 " >退款中</div>
            <div v-else-if="scope.row.tousuStatus == 2 && scope.row.handleType == 2 && scope.row.orderStatus ==12 ">已退款</div>
            <div v-else></div>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
      <el-dialog :title="title" :close-on-click-modal="false" :visible.sync="open" width="500px" append-to-body>
        <div class="popupCont" v-if="!inputDisabled">{{ tousuDesc }}</div>
        <el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="replyContent" v-if="inputDisabled"></el-input>
        <div slot="footer" class="quesEditBtn">
          <el-button type="primary" @click="submit" v-if="inputDisabled">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
      <el-dialog title="申请退款" :close-on-click-modal="false" :visible.sync="applyOpen" width="300px" append-to-body>
        <el-form ref="pupopForm" :model="pupopForm" :rules="rules" label-width="80px">
          <el-form-item label="订单编号" prop="orderNo">
            <el-input v-model="pupopForm.orderNo" placeholder="请输入订单编号" />
          </el-form-item>
          <el-form-item label="用户名" prop="person">
            <el-input v-model="pupopForm.person" placeholder="请输入用户名" />
          </el-form-item>
          <el-form-item label="用户电话" prop="personPhone">
            <el-input v-model="pupopForm.personPhone" placeholder="请输入用户电话" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="quesEditBtn">
          <el-button type="primary" @click="applySubmit">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
      <el-dialog :visible.sync="picShow" title="投诉截图">
        <el-image style="width: 100px; height: 100px;margin:0 10px 10px 0" :src="item.url"  v-for="(item,index) in srcList" :preview-src-list="[item.url]"> </el-image>
      </el-dialog>
      </div>
  </template>
    
  <script>
  import { tousuList,tousuRefund,tousuReply} from "@/api/feedback/feedback";
  import { getToken } from '@/utils/auth'
  export default {
    name: "Knowledge",
    components: {
    },
    data() {
      return {
        // 遮罩层
        loading: false,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 表格数据
        tabList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        applyOpen:false,
        picShow:false,
        companyTypeOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          createDay:null,
          jishiNickName:null,
          tousuType:null,
          handleType:null
        },
        rules:{
          orderNo:[
            { required: true, message: "订单编号不能为空", trigger: "blur" }
          ],
          person:[
            { required: true, message: "用户名不能为空", trigger: "blur" }
          ],
          personPhone:[
            { required: true, message: "请输入手机号", trigger: "blur" },
            {
            pattern: /^0{0,1}(13[0-9]|16[0-9]|15[0-9]|18[0-9]|17[0-9]||19[0-9])[0-9]{8}$/,
            message: '手机号格式不对！',
            trigger: 'blur'
          }
          ],
        },
        tousuTypeArray:[],//投诉类型
        handleTypeArray:[],//解决类型
        inputDisabled:false,
        replyContent:'',
        tousuDesc:'',
        id:'',
        pupopForm:{},
        srcList:[]
      };
    },
    created() {
      this.getList();
      //在字典查询-解决类型
      this.getDicts("handle_type").then(response => {
        this.handleTypeArray = response.data;
      });
      //投诉类型
      this.getDicts("tousu_type").then(response => {
        this.tousuTypeArray = response.data;
      });
      this.getDicts("category").then(response => {
        this.tousuTypeArray = this.tousuTypeArray.concat(response.data);
      });
    },
    methods: {
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 查询产品入库列表 */
      getList() {
        this.loading = true;
        tousuList(this.queryParams).then(response => {
          this.tabList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      //查看备注
      lookTousuDesc(row){
        this.tousuDesc = row.tousuDesc
        this.title = '投诉内容'
        this.inputDisabled = false
        this.open = true
      },
      //回复
      replyClick(row){
        this.title = '回复'
        this.open = true
        this.inputDisabled = true
        this.id = row.id
      },
      //回复确定
      submit(){
        tousuReply({replyContent:this.replyContent,id:this.id}).then(response => {
          if(response.code === "200"){
            alert(1)

            this.msgSuccess(response.msg);
            this.open = false
            this.getList()
          }
        });
      },
      applyClick(row){
        this.pupopForm.id = row.id
        this.applyOpen = true
      },
      applySubmit(){
        this.$refs["pupopForm"].validate(valid => {
          if (valid) {
            tousuRefund(this.pupopForm).then(response => {
              if(response.code == "200"){
                this.$message(response.msg);
                this.applyOpen = false
                this.getList()
              }
            });
          }
        });
      },
      imgUrlClick(row){
        this.srcList = []
        if (row.imgUrl) {
            this.srcList = JSON.parse(row.imgUrl);
        }
        this.picShow = true
      },
      cancel(){
        this.open=false
        this.applyOpen = false
      }
    }
  };
  </script>
  <style>
  .popupCont{
      min-height: 80px;
      padding: 10px ;
      font-size: 14px;
      color:#333;
      border-radius: 6px;
      border:1px solid #999;
    }
    .quesEditBtn{
      text-align: center;
    }
  </style>
    